feat: add VS Code/Copilot integration for tool-agnostic sessions (fixes #7)#16
Conversation
|
This is very much appreciated 🙏 Will check this out as soon as I can. Thanks for your contribution. |
|
@bilersan there are minor linter issues; not a blocker, but would be cool if you can fix them before I jump in 🙏 . |
Add tool-agnostic session parser that reads structured Markdown files from .context/sessions/, enabling non-Claude tools (Copilot, Cursor, Windsurf) to participate in the recall/journal pipeline. Changes: - Add config constants: ToolClaudeCode, ToolMarkdown, DirSessions - Implement MarkdownSessionParser with support for multiple header formats (# Session: YYYY-MM-DD - Topic, etc.) - Register markdown parser alongside ClaudeCodeParser - Scan .context/sessions/ for markdown session files - Replace hardcoded 'claude-code' strings with config constants - Add comprehensive parser tests (390 lines) Refs: ActiveMemory#7 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
Add --write flag to 'ctx hook copilot' that generates .github/copilot-instructions.md directly instead of just printing the configuration snippet. The generated instructions teach Copilot Chat (agent mode) to: - Read .context/ files in priority order at session start - Persist session summaries to .context/sessions/ - Proactively update context files during work - Respond to memory queries with structured readbacks Also creates .context/sessions/ during ctx init so the session persistence workflow is ready out of the box for all tools. Refs: ActiveMemory#7 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
Add @ctx chat participant for VS Code Copilot Chat that wraps ctx CLI commands as slash commands. Users can type @ctx /init, @ctx /status, @ctx /drift, etc. directly in the Chat panel. Slash commands: - /init - Initialize .context/ + auto-generate copilot-instructions.md - /status - Show context summary with token estimate - /agent - Print AI-ready context packet - /drift - Detect stale or invalid context - /recall - Browse and search session history - /hook - Generate AI tool integration configs - /add - Add task, decision, or learning - /load - Output assembled context Markdown - /compact - Archive completed tasks - /sync - Reconcile context with codebase The extension executes the ctx binary and streams results back to chat. Includes CancellationToken support for aborting long-running calls, follow-up suggestions, and natural language routing. Also includes: - 11 colocated unit tests (vitest) - esbuild ^0.25.0 (resolves GHSA-67mh-4wv8-2f99) Refs: ActiveMemory#7 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- Add VS Code Chat Participant section to integrations.md with build/install instructions and slash command reference - Document copilot --write flag in cli-reference.md - Add Copilot session persistence to first-session.md - Update getting-started.md with VS Code extension install steps - Fix vsix version reference (0.6.0 -> 0.7.0) Refs: ActiveMemory#7 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- Add filepath.Clean for os.ReadFile in hook/run.go (gosec G304) - Export ToolConfigFiles var in hook/run.go (unused) - Add goconst nolint directives for trivial yes comparisons
Test files construct paths from test constants, not user input. This matches the goconst exclusion already in place.
c376022 to
a2ad811
Compare
|
@josealekhine Linter issues are fixed! Here's what was done: Rebased on latest Lint fixes (3 new commits):
Verification:
Ready for review whenever you have time 🙏 |
josealekhine
left a comment
There was a problem hiding this comment.
PR-16 Review: VS Code / Copilot Integration
Validation Summary
| Step | Result |
|---|---|
| PR-16.1 Baseline capture (main) | 250 entries, 289 markdown files |
| PR-16.2 Apply PR + full test suite | All tests pass (4.064s parser pkg) |
| PR-16.3 Semantic diff (journal pipeline) | Zero diff — identical output |
| PR-16.4 Code quality review | Approve with minor suggestions |
What's Good
- MarkdownSessionParser cleanly implements
SessionParserinterface. Registration, matching, parsing all correct. - Backward compatibility confirmed: journal pipeline produces byte-identical output on main vs this branch.
- Copilot instructions template is comprehensive — read order, session persistence format, context update table, self-check prompt.
- VS Code extension is well-structured: cancellation token handling, configurable path, follow-up suggestions, natural language fallback.
- Test coverage is solid: 391 lines of Go parser tests (23+ subtests), 185 lines of VS Code tests (7 runCtx scenarios).
- Constants extraction (
ToolClaudeCode,ToolMarkdown,RoleUser, etc.) improves maintainability. - Documentation is thorough — integrations.md expanded from 12 to ~100 lines, getting-started and first-session updated.
Minor Suggestions (Non-Blocking)
-
Map iteration order (
markdown.go:185):for heading, body := range sectionsiteratesmap[string]stringnon-deterministically. ThebodyPartsslice (and resulting assistant message text) may vary in order between runs. Consider sorting section keys or using an ordered representation. Not a correctness bug — content is identical regardless — but affects reproducibility. -
--no-colorinconsistency in VS Code extension:handleAgent(L142) andhandleLoad(L269) don't pass--no-color, whilehandleStatus,handleDrift,handleCompact,handleSync, andhandleInitall do. These commands may not produce colored output today, but adding the flag would be more consistent. -
Potential double-counting in
query.go: If.context/sessions/is also passed as anadditionalDirsargument, sessions could appear twice. Low probability in practice but could be guarded with a seen-paths set. -
handleHookalways passes--write(extension.ts:207): Users can't preview hook output via the extension — it always writes to disk. Consider making--writeoptional or adding a dry-run note.
Verdict
Approve. The PR is well-structured, fully tested, backward-compatible, and follows project conventions. The minor items above are polish — none block merge.

Summary
Adds first-class VS Code and GitHub Copilot support to ctx, delivering the tool-agnostic session persistence pipeline proposed in #7.
This PR introduces three tightly coupled components that together enable Copilot Chat to read and write ctx sessions without requiring users to leave their editor.
What's Included
1. Tool-Agnostic Session Parser (internal/recall/parser/markdown.go)
MarkdownSessionParserthat reads.context/sessions/*.mdfiles# Session,##, YAML frontmatter)2. Copilot Hook + Init Updates (internal/cli/hook/,
internal/cli/initialize/)ctx hook copilot --writegenerates.github/copilot-instructions.mdwith ctx-aware system promptctx initnow creates.context/sessions/directory for session storagetoolConfigFilesmap for extensible tool config discovery3. VS Code Chat Participant Extension (
editors/vscode/)@ctxchat participant with 10 slash commands:/init,/load,/save,/status,/list,/search,/config,/help,/version,/recallWhat's Intentionally Excluded
This PR is scoped to VS Code and GitHub Copilot only. The following exist on the feature branch but are held back for separate PRs:
--toolflag onctx initTesting
go build ./...clean, all new parser and hook tests passnpm run buildclean (7.6 KB), 11/11 vitest tests pass,npm audit0 vulnerabilitiesConnects To
Issue #7 — specifically the proposed architecture of
ctx hook <tool> --writegenerating tool-specific instruction files, with editor extensions acting as the bridge between the tool's chat interface and ctx's session storage.